<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

const userActions = ref([
  { icon: 'icon-message', label: '消息' },
  { icon: 'icon-collection', label: '收藏' },
  { icon: 'icon-history', label: '历史' },
  { icon: 'icon-light', label: '创作中心' }
])
</script>

<template>
  <div class="header-bar">
      <!-- Logo区域 -->
      <div class="header-section">
        <router-link to="/" class="logo-link">
          <span class="iconfont icon-logo">首页</span>
        </router-link>
      </div>

      <!-- 搜索区域 -->
      <div class="header-section">
        <div class="search-box">
          <el-input
            placeholder="搜索内容..."
            clearable
            :maxlength="150"
            class="search-input"
          >
            <template #suffix>
              <span class="iconfont icon-search"></span>
            </template>
          </el-input>
        </div>
      </div>

      <!-- 用户功能区 -->
      <div class="header-section">
        <div class="user-panel">
            <div class="user-avatar">
            <img src="../assets/user.png" alt="用户头像">
          </div>

          <div 
            class="user-action" 
            v-for="(action, index) in userActions" 
            :key="index"
          >
            <span class="iconfont" :class="action.icon"></span>
            <span class="action-label">{{ action.label }}</span>
          </div>
        
          <el-button type="danger" class="upload-btn">
            <span class="iconfont icon-upload"></span>
            <span>投稿</span>
          </el-button>
        </div>
      </div>
    </div>
</template>

<style scoped>
/* 头部栏布局 */
.header-bar {
  display: flex;
  width: 100%;
  height: 80px;
  padding: 0 25px; /* 确保左右边距25px */
  align-items: center;
  box-sizing: border-box; /* 确保padding包含在宽度内 */
}

/* 三个模块调整 */
.header-section {
  display: flex;
}

/* 左边模块靠左 */
.header-section:first-child {
  justify-content: flex-start;
  flex: 1;
}

/* 中间模块居中 */
.header-section:nth-child(2) {
  justify-content: center;
  flex: 1;
}

/* 右边模块靠右 */
.header-section:last-child {
  justify-content: flex-end;
  flex: 1;
}

/* Logo样式 */
.logo-link {
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-link .iconfont {
  font-size: 36px;
  color: white;
}

/* 搜索框样式 */
.search-box {
  width: 100%;
  max-width: 400px;
}

.search-input :deep(.el-input__wrapper) {
  border-radius: 20px;
  background-color: rgba(255, 255, 255, 0.9);
}

.search-input :deep(.el-input__inner) {
  color: #333;
}

/* 用户功能区样式 */
.user-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 15px; /* 缩小间距 */
}

.user-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.user-action .iconfont {
  font-size: 20px;
  color: white; /* 初始白色 */
}

.action-label {
  font-size: 12px;
  color: white; /* 初始白色 */
  margin-top: 2px;
}

/* 用户头像 */
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  margin-left: 10px;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 投稿按钮 */
.upload-btn {
  border-radius: 20px;
  padding: 8px 16px;
  margin-left: 15px;
  background: linear-gradient(to right, #ff4d4f, #ff7875);
  border: none;
  box-shadow: 0 2px 8px rgba(255, 77, 79, 0.3);
}

.upload-btn:hover {
  background: linear-gradient(to right, #ff7875, #ff4d4f);
}

.upload-btn .iconfont {
  margin-right: 5px;
  font-size: 14px;
}

/* 响应式处理 */
@media (max-width: 1600px) {
  .user-action {
    padding: 0 8px;
  }
}

@media (max-width: 1400px) {
  .action-label {
    display: none;
  }
  .user-panel {
    gap: 10px;
  }
}
</style>